// let base_url = '/apis'
let base_url = '/baseUrlTest/apis'
import Vue from "vue"
import {
	msg,
	to
} from "./uilt/index.js"
import {
	parse
} from "qs"
import {
	toUrl
} from "./url"
let http = (url, method, data, header) => {
	uni.showLoading({
		title: "加载中"
	});
	return new Promise((resolve, reject) => {
		let userData = uni.getStorageSync('userData');
		uni.request({
			url: base_url + url,
			method,
			header: {
				'content-type': "application/json",
				satoken: userData.satoken,
			},
			data,
			success(res) {
				uni.hideLoading();
				res = res.data
				console.log(res.code);
				if (res.code === 200) {
					resolve(res)
					return
				} else if (res.code === 400101) {
					window.location.replace(toUrl)
					msg("验证失败，请重新登录")
					return
				} else if (res.code === 400102) {
					msg("登录失败，请联系管理员")
					return
				}
				return (msg(res.msg))
			},
			fail(err) {
				reject(err)
			},
			complete() {
				uni.hideLoading();
			}
		})
	})
}
export let get = function(url, data = {}) {
	return http(url, 'get', parse(data))
}
export let post = (url, data) => {
	return http(url, "post", data)
}